package cn.yunhe.controller;

import cn.yunhe.model.Admin;
import cn.yunhe.service.AdminService;

public class AdminAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private Admin admin;
	private String target;
	private String newpassword;
	
	AdminService adminService = new AdminService();

	public String queryAdmin() {
		getMapRequest().put("listAdmin", adminService.searchAllAdmin());
		this.setTarget("list");
		return "query";
	}

	public String addAdmin() {
		this.setTarget("admin_query");
		return adminService.addAdmin(admin) ? SUCCESS : ERROR;
	}

	public String deleteAdmin() {
		this.setTarget("admin_query");
		return adminService.deleteAdmin(admin) ? SUCCESS : ERROR;
	}
	
	public String loginAdmin(){
		this.setTarget("admin_query");
		return adminService.loginAdmin(admin) != null ? SUCCESS : ERROR; 
	}

	public String updateAdmin(){
		admin.setPassword(newpassword);
		this.setTarget("admin_query");
		return adminService.updateAdmin(admin) ? SUCCESS : ERROR;
	}
	
	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}
	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public String getNewpassword() {
		return newpassword;
	}

	public void setNewpassword(String newpassword) {
		this.newpassword = newpassword;
	}


}
